package Package.IOStream.CharacterStream.DataWrite;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class DataWrite {
<<<<<<< HEAD
    public static final void DataWrite(){

=======
    public static final void DataWrite() throws IOException {
        OutputStreamWriter OSW=new OutputStreamWriter(new FileOutputStream("D:\\insert\\a.txt"));
>>>>>>> e5a6e7b43893e47880bebc66242b3c545118f707
//        void write(int c) 写一个字符
OSW.write(47);

//void write(char[] cbuf) 写入一个字符数组
OSW.write(new char[]{'a', 'b', 'c'});
//void write(char[] cbuf, int off, int len) 写入字符数组的一部分
OSW.write(new char[]{'1','2','3','4'},0,2);
//void write(String str) 写一个字符串
        OSW.write("ChangCun");
//void write(String str, int off, int len) 写一个字符串的一部分
OSW.write("YangYinTao",0,5);

//        刷新和关闭的方法
//        flush() 刷新流，之后还可以继续写数据
OSW.flush();
OSW.write("K");
//close() 关闭流，释放资源，但是在关闭之前会先刷新流。一旦关闭，就不能再写数据
        OSW.close();
//        OSW.write("HaiJun");报错字符流结束
    }
}
